package cn.yunhe.biz.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.yunhe.biz.IZhuYuanBiz;
import cn.yunhe.dao.ZhuyuanMapper;
import cn.yunhe.entity.Zhuyuan;
import cn.yunhe.entity.ZhuyuanExample;
@Service("zyBiz")
public class ZhuYuanBizImpl implements IZhuYuanBiz {
	@Autowired
	private ZhuyuanMapper zyMapper;
	
	public void setZyMapper(ZhuyuanMapper zyMapper) {
		this.zyMapper = zyMapper;
	}

	@Override
	public Integer AddZhuYuan(Zhuyuan zhuyu) {
		// TODO Auto-generated method stub
		Integer flag = 0;
		try {
			flag = zyMapper.insert(zhuyu);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return flag;
	}
	
	
	@Override
	public List<Zhuyuan> FindAllZhuyuan() {
		// TODO Auto-generated method stub
		List<Zhuyuan> list = null;
		try {
			list = zyMapper.selectByExample(null);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public Zhuyuan FindZhuyuanById(Integer ID) {
		// TODO Auto-generated method stub
		List<Zhuyuan> list = null;
		try {
			ZhuyuanExample example = new ZhuyuanExample();
			ZhuyuanExample.Criteria crita = example.createCriteria();
			crita.andHosrIdEqualTo(ID);
			list = zyMapper.selectByExample(example);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list.get(0);
	}

	@Override
	public boolean UpdateZhuyuanById(Zhuyuan zhuyu, Integer id) {
		// TODO Auto-generated method stub
		Integer flag = 0;
		try {
			ZhuyuanExample example = new ZhuyuanExample();
			ZhuyuanExample.Criteria crita = example.createCriteria();
			crita.andHosrIdEqualTo(id);
			flag = zyMapper.updateByExample(zhuyu, example);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(flag>0){
			return true;
		}else{
			return false;	
		}
	}

}
